/*
 * @lc app=leetcode.cn id=228 lang=javascript
 *
 * [228] 汇总区间
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {string[]}
 */
var summaryRanges = function (nums) {
  const res = [];
  let start = 0;
  let end = 0;
  while (end < nums.length) {
    if (nums[end] === nums[end + 1] - 1) {
      end++;
    } else {
      if (end === start) {
        res.push(`${nums[start]}`);
        start++;
        end++;
      } else {
        res.push(`${nums[start]}->${nums[end]}`);
        start = end + 1;
        end = start;
      }
    }
  }
  return res;
};
// @lc code=end
